package com.rjpacket.chileme.app.tasks;

import android.os.AsyncTask;
import com.rjpacket.chileme.app.Constants;
import com.rjpacket.chileme.app.utils.HttpTool;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.UnsupportedEncodingException;

/**
 * Created by Administrator on 2015/3/24 0024.
 */
public class HeadTask extends AsyncTask<String,Integer,JSONObject>{

    private Process process;

    public HeadTask(Process process) {
        this.process = process;
    }

    @Override
    protected JSONObject doInBackground(String... strings) {
        JSONObject ret = null;
        byte[] bytes = HttpTool.get(Constants.MAIN_SHOW_URL);
        if (bytes != null) {
            try {
                String str = new String(bytes,"UTF-8");
                ret = new JSONObject(str);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return ret;
    }

    @Override
    protected void onPostExecute(JSONObject jsonObject) {
        if (process != null) {
            process.processResult(jsonObject);
        }
    }
}
